package com.changgou.canal.config;

import com.changgou.common.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {

    //定义队列
    @Bean("spuQueue")
    public Queue spuQueue(){
        return QueueBuilder.durable(RabbitMQConstant.SPU_TOPIC_QUEUE).build();
    }

    //定义交换机
    @Bean("spuExchange")
    public Exchange spuExchange(){
        return ExchangeBuilder.directExchange(RabbitMQConstant.SPU_TOPIC_EXCHANGE).build();
    }

    //绑定队列与交换机
    @Bean("spuBinding")
    public Binding spuBinding(@Qualifier("spuQueue") Queue queue,@Qualifier("spuExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(RabbitMQConstant.SPU_TOPIC_QUEUE).noargs();
    }

}
